package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.OverflowListGoods;
import com.atguigu.jxc.service.OverflowListService;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *OverflowList
 * @author Mr.zhao
 * @version 1.0
 * @date 2022/1/4 10:58
 */
@RequestMapping("/overflowListGoods")
@RestController
public class OverflowListController {

    @Autowired
    private OverflowListService overflowListService;

    @PostMapping("/save")
    public ServiceVO save(OverflowList overflowList,
                          String overflowListGoodsStr,

                          HttpSession session){

        ObjectMapper objectMapper = new ObjectMapper();
        try {
            List<OverflowListGoods> readValue = objectMapper.readValue(overflowListGoodsStr, new TypeReference<List<OverflowListGoods>>() {
            });


            overflowListService.save(overflowList,session,readValue);

            return ServiceVO.Ok();
        } catch (Exception e) {
            e.printStackTrace();
            return ServiceVO.error(e.getMessage());
        }
    }
    @PostMapping("/list")
    public Map<String, Object> getList(String  sTime, String  eTime){
        return overflowListService.getList(sTime,eTime);
    }

    @PostMapping("/goodsList")
    public Map<String, Object> getGoodsList(Integer overflowListId){
        return overflowListService.getGoodsList(overflowListId);
    }


}
